<?php

declare(strict_types=1);

namespace App\Job\Order;

use App\Constants\Order\OrderCode;
use App\Model\Orders\Order as OrderModel;
use Hyperf\AsyncQueue\Job;
use App\Services\Orders\Order as OrderServices;
use function Hyperf\Support\make;

class Expire extends Job
{
    /**
     * 参数
     * @var array
     */
    protected array $param;

    /**
     * 尽量不要将 Container，Config 等设置为成员变量。 同理 #[Inject] 也是如此
     * AutoCancelOrderJob constructor.
     * @param $param
     */
    public function __construct(array $param)
    {
        $this->param = $param;
    }

    /**
     *
     */
    public function handle()
    {
        [$orderId] = $this->param;
        /** @var OrderServices $orderServices */
        $orderServices = make(OrderServices::class);
        /** @var OrderModel $orderModel */
        $orderModel = $orderServices->findOrFail($orderId);
        if ($orderModel->status === OrderCode::STATUS_PENDING_PAID) {
            $orderModel->fill([
                'status' => OrderCode::STATUS_CLOSE
            ])->save();
        }
    }
}
